package my.sample.channel.datagram.nochannel;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.nio.ByteBuffer;

public class NewClient {

  public static void main(String[] args) throws Exception {
    DatagramSocket s = new DatagramSocket();

    InetAddress hostAddress = InetAddress.getByName("210.210.122.122");
    
    byte[] text = "ffffffffffffffffffffffffffffffffffffffffffffffffff".getBytes();
    ByteBuffer payload = ByteBuffer.allocate(1000);
    for ( int i = 0; i < 1000 ; i += 50 )
			payload.put(text); 
    
    int count = 0;
    
    
//    System.exit(1);
		while (true) {

//			System.out.print(".");
			payload.flip();
			payload.putInt(count++);
			payload.flip();
			byte[] buf = new byte[1000];
			payload.limit(1000);
			payload.get(buf, 0, 1000);

			DatagramPacket out = new DatagramPacket(buf, buf.length, hostAddress, 9999);
			s.send(out);
			
			if ( count > 100000 )
				System.exit(1);
			
			try {
				Thread.sleep(2);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
  }
}